package com.matongxue.springboot.user.service.impl;

import com.matongxue.springboot.user.dao.ApiTestCaseMapper;
import com.matongxue.springboot.user.dao.TbBusniesDao;
import com.matongxue.springboot.user.entity.TbBusnies;
import com.matongxue.springboot.user.service.TbBusniesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 业务场景测试参数(TbBusnies)表服务实现类
 *
 * @author makejava
 * @since 2022-10-19 21:55:01
 */
@Service("tbBusniesServiceImpl")
public class TbBusniesServiceImpl implements TbBusniesService {
    @Resource
    private TbBusniesDao tbBusniesDao;

    @Autowired
    ApiTestCaseMapper apiTestCaseMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public TbBusnies queryById(Long id) {
        return this.tbBusniesDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param tbBusnies   筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<TbBusnies> queryByPage(TbBusnies tbBusnies, PageRequest pageRequest) {
        long total = this.tbBusniesDao.count(tbBusnies);
        return new PageImpl<>(this.tbBusniesDao.queryAllByLimit(tbBusnies, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param tbBusnies 实例对象
     * @return 实例对象
     */
    @Override
    public TbBusnies insert(TbBusnies tbBusnies) {
        this.tbBusniesDao.insert(tbBusnies);
        return tbBusnies;
    }

    /**
     * 修改数据
     *
     * @param tbBusnies 实例对象
     * @return 实例对象
     */
    @Override
    public TbBusnies update(TbBusnies tbBusnies) {
        this.tbBusniesDao.update(tbBusnies);
        return this.queryById(tbBusnies.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.tbBusniesDao.deleteById(id) > 0;
    }
}
